/*******************************************************************************************
Copyright (C) 2013 Mestrelab Research S.L. All rights reserved.

This file is part of the MNova scripting toolkit.

Authorized users of MNova Software may use this file freely, but this file is provided AS IS
with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE.
*******************************************************************************************/
/*jslint  */
/*global File, Process, print, Dir, TextStream*/

function processTest() {
	'use strict';
	var fileName,
		f,
		s;
	fileName  = Dir.temp() + "/MNova_Process_Text.txt";
	f = new File(fileName);
	f.open(File.WriteOnly);
	s = new TextStream(f);
	s.write("Hello Notepad!");
	f.close();
	print(Process.execute("notepad.exe", fileName));

	f.open(File.ReadWrite);
	s.pos = f.size;
	print(s);
	s.write("\r\nHi again!");
	f.close();
	print(Process.startDetached("notepad.exe", fileName));
}

function processTestAdv() {
	'use strict';
	var proc = new Process();

	proc.started.connect(function () { MessageBox.information("Process Started!"); });
	proc["finished(int)"].connect(proc, function (aExitCode, aStatus) { MessageBox.information("Process Finished. Exit Code %1.".arg(aExitCode)); print(this.allStdOutput); print(this.allErrorOutput);});
	proc.start('ls', ['-lh', '/home/']);
	if (!proc.waitForStarted()) {
		MessageBox.critical("Failed to Start");
	}
}
